define(function(require, exports, module) {

	var $ = require('jquery');
	var List = require('../util/list');
	require('artTemplate/artTemplate/2.0.1/template.js');
	require('seajs/seajs/2.1.1/sea.js');

	exports.options = {
		listLink : '',
		listParams : '',
		pageLink : '',
		pageParams : ''
	};
	var v = $('.nav-tabs .active').attr("id");
	var provinceId = 0;
	var cityId = 0;
	var districtId = 0;

	exports.showOrgVerify = function showOrgVerify(e) {
		var orgList = new List();
		orgList.options.template = "verifyOrgList-template";
		orgList.options.container = "#list";
		orgList.options.links = {
			"list" : $CONFIG.base_url + "/api/institution/list"
		};
		orgList.options.params = {
			"status" : e,
			"s" : 10
		};
		orgList.load(function(){
			$(".modal-body").each(function(){
				provinceId = $(this).find("input[id=provinceId]").val();
				cityId = $(this).find("input[id=cityId]").val();
				districtId = $(this).find("input[id=districtId]").val();
				//var provinceName = exports.getProvince(provinceId);
				exports.getCity(provinceId, cityId, districtId, $(this));	
			})
		});
	};

	// 三级城市id转换成三级城市名
	exports.getCity = function(provinceId, cityId, districtId, e){
		$.get($CONFIG.base_url + "/api/region/list/parent", {
			parentId : 0
		}, function(data) {
			var name = '';

			for(var i=0;i<data.length;i++){
				if(provinceId == data[i].id){
					name += data[i].name;
					$.get($CONFIG.base_url + "/api/region/list/parent", {
						parentId : data[i].id
					}, function(data) {
						for(var j=0;j<data.length;j++){
							if(cityId == data[j].id){
								name+=data[j].name;
								$.get($CONFIG.base_url + "/api/region/list/parent", {
									parentId : data[j].id
								},function(data){
									for(var k=0;k<data.length;k++){
										if(districtId == data[k].id){
											name+=data[k].name;
											e.append('<p>地区：'+name+'</p>');
											//console.log($(this));
											//$(this).append('<p>地址：'+name+'</p>');
										}
									}
								})
							}
						}
					})
				}
					
			}
		})
	}

	exports.showFameVerify = function showOrgVerify(e) {
		var fameList = new List();
		fameList.options.template = "verifyFameList-template";
		fameList.options.container = "#list";
		fameList.options.links = {
			"list" : $CONFIG.base_url + "/api/charitarian/list"
		};
		fameList.options.params = {
			"status" : e,
			"s" : 10
		};
		fameList.load();
	};
	$(document).ready(function(data) {
		exports.showOrgVerify("0");
	});

	$("#list").on('change', '#jg-status', function() {
		exports.showOrgVerify($(this).val());
	});


	$("#list").on('change', '#zrj-status', function() {
		exports.showFameVerify($(this).val());
	});

	$("#institution").click(function() {
		exports.showOrgVerify("0");
	});

	$("#charitarian").click(function() {
		exports.showFameVerify("0");
	});

	//预览认证资料
	$("#list").on('mouseenter','.download',function() {
		$("#pic-view img").attr("src",$(this).attr('href'));
		$("#pic-view").addClass('hover');
		$("#pic-view").css("display", "block");
		
	});
	$("#list").on('mouseleave','.download',function() {
		$("#pic-view").css("display", "none");
	});

});